Dynomotion

Group: DynoMotion Message: 1903 From: soyuzpilot Date: 10/8/2011
Subject: Mach3 speed control w/ brushless motor driver
I am trying to get a new brushless motor driver http://www.kelinginc.com/CNCmillingcontroller.html working with Mach3 speed control via my KFLOP and was hoping to get some clarification before I went and broke something.

Looking at the manual, page 10
http://www.cnczone.com/forums/attachment.php?attachmentid=111182&d=1279486851

it shows the external user interface port for PWM control. Specifically (in case the manual won't load for you) it has:

Pin 4, Start/Stop in the shutdown state to a negative pulse start, turned down in a negative pulse stopped, a negative pulse every time a status change.

Pin 5, Forward/Reverse: Positive/negative inversion pulse every time a status change

Pin 6: PWM control input, 500-5Khz of the PWM control signal, 10%-90% of the minimum speed can be controlled to the highest (Recommended frequency: 1Khz)


Starting with Pin 6, I read this to mean I should set a 1Khz frequency period and then vary the duty cycle from 10% to 90% to control speed. I have seen previous posts describing how to set PWM pre_scale and duty cycle. However I am unclear exactly what I should set in Mach3 in order to enable the speed control and send the proper notify to the control program. Do I need to configure Relay Control output pins in the spindle settings tab? How about the motor control PWM base frequency? It seems like this should all be controlled by the KFLOP and irrelevant to a notify message.

I've seen a post with a sample SpindleMach3PWM.c program:

#include "KMotionDef.h"

//Plugin Notifications and defines..
enum { EX_DDA , EX_VMS, EX_COMMAND, EX_SPINON, EX_SPINOFF, EX_SPINSPEED, EX_MOTORTUNED
, EX_SETUP, EX_FEEDHOLD, EX_RUN, EX_ESTOP , EX_CONFIG };

main()
{
int message = persist.UserData[0]; // Mach3 message ID
int Direction = persist.UserData[1]; // Mach3 Spindle Direction
float speed = *(float *)&persist.UserData[2]; // value stored is actually a float

printf("Mach3 Notify Message=%d, Direction=%2d, Spindle Set to %f\n",message,Direction,speed);

switch (message)
{
case EX_SPINSPEED:
printf("Spindle Speed Set to %f\n",speed);

SetBitDirection(26,1); // define bit as an output

FPGA(IO_PWMS_PRESCALE) = 65; // divide clock by 65 (1 KHz)

FPGA(IO_PWMS) = (unsigned char)(255.0f*speed); // set period

FPGA(IO_PWMS+1) = 1; // Enable


break;

case EX_SPINON:
if (Direction==0)
{
printf("Spindle CW ON\n");
SetBit(144);
ClearBit(145);
}
else if (Direction==1)
{
printf("Spindle CCW ON\n");
ClearBit(144);
SetBit(145);
}
break;

case EX_SPINOFF:
{
printf("Spindle Stop\n");
FPGA(IO_PWMS) = 0; // turn off PWM

ClearBit(144);
ClearBit(145);
}
break;
}
}


Which seems to indicate the Mach3 notify will provide me with a "SpindleSpeed" event followed by either "SpindleOn" event specifying direction, or a "SprindleOff" event. When is the SpindleSpeed event sent? Does it always occur immediately prior to a SpindleOn event or is it only when Mach3 senses a change in the spindle speed (from clicking on the GUI or a GCode block)? What I am concerned about is knowing how much error control to worry about in regards to initialization.


Finally this leaves controlling direction and start/stop. I understand WHERE in the c switch I should process these events but I'm afraid that my ignorance of PWM, and TTL combined with the possibility that the manual is not a particularly high-quality english translation means that I am not certain how to interpret what signals I should be sending to the driver's pins 4 and 5 nor, once that is established, how to produce such signals via the KFLOP.

On Pin 5, is "Positive/negative inversion pulse" a particular kind of TTL or PWM signal or does that mean I should pulse (turn on/off quickly) a positive voltage to go forwards and a negative voltage to go in reverse? Or something else entirely?

On Pin 6 I am at a complete loss, other than to be left wondering exactly how one generates a negative pulse via the KFLOP at all.
Group: DynoMotion Message: 1904 From: Tom Kerekes Date: 10/8/2011
Subject: Re: Mach3 speed control w/ brushless motor driver
Hi Shawn,
 
Yes the manual is not very clear at best.
 
It supposedly works with Mach3 generating a PWM on the parallel port so it should work with KFLOP.
 
As a first step figure out and verify that you can control the motor from KFLOP without attempting to use Mach3 at all.  Use the PWM1KHz.c example to experiment with controlling the speed.  Also toggle the Direction bit from the Digital I/O screen to verify you can control direction.
 
If that all works you can then interface it to Mach3 using something like the SpindleMach3PWM.c example.
 
To understand which messages are sent when and in what order by Mach3 you can use the SpindleMach3.c example this example does nothing except print the messages it receives from Mach3.  Basically as you would expect whenever the Spindle Speed is supposed to change from a GUI button or GCode messages are sent.  All the outputs PWM, on/off, and direction are controlled by KFLOP so they don't need to be configured in Mach3.  However if you select Disable Spindle Relays in Mach3 then Mach3 will not send all the spindle messages to the Plugin.
 
 Regarding a negative pulse I have no clue what they mean either.  But if the PWM pulse needs to be inverted you can do that by complementing the duty cycle value (y=255-x).  So for example a duty cycle 90% high pulse can also be thought of as a 10% low going pulse.
 
Hope this helps and good luck.
 
TK     
 

Group: DynoMotion Message: 1909 From: soyuzpilot Date: 10/8/2011
Subject: Re: Mach3 speed control w/ brushless motor driver
Thanks, I guess I need to pay more attention to the KFLOP's console when using Mach3, I've always just shut one down when starting the other. Once I get the proper cable connector to interface with this new driver I'll try out your advice of just playing with it in KMotion and seeing what happens. In the mean time I guess I'll ping some of the threads where this driver is being used by parallel port guys and see if any of them understand what it wants.



--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Shawn,
>  
> Yes the manual is not very clear at best.
>  
> It supposedly works with Mach3 generating a PWM on the parallel port so it should work with KFLOP.
>  
> As a first step figure out and verify that you can control the motor from KFLOP without attempting to use Mach3 at all.  Use the PWM1KHz.c example to experiment with controlling the speed.  Also toggle the Direction bit from the Digital I/O screen to verify you can control direction.
>  
> If that all works you can then interface it to Mach3 using something like the SpindleMach3PWM.c example.
>  
> To understand which messages are sent when and in what order by Mach3 you can use the SpindleMach3.c example this example does nothing except print the messages it receives from Mach3.  Basically as you would expect whenever the Spindle Speed is supposed to change from a GUI button or GCode messages are sent.  All the outputs PWM, on/off, and direction are controlled by KFLOP so they don't need to be configured in Mach3.  However if you select Disable Spindle Relays in Mach3 then Mach3 will not send all the spindle messages to the Plugin.
>  
>  Regarding a negative pulse I have no clue what they mean either.  But if the PWM pulse needs to be inverted you can do that by complementing the duty cycle value (y=255-x).  So for example a duty cycle 90% high pulse can also be thought of as a 10% low going pulse.
>  
> Hope this helps and good luck.
>  
> TK     
>  
>
Group: DynoMotion Message: 1911 From: soyuzpilot Date: 10/9/2011
Subject: Re: Mach3 speed control w/ brushless motor driver
http://dynomotion.com/Help/PWM_Description/PWM_Description.htm

Does the KFlop support both Normal and Recirculating mode, or just normal mode? If both, how do I specify which to use?

I am beginning to wonder if perhaps the F/R and/or Start/Stop pins are wanting a PNP style current sinking switch. I need to get around to contacting the manufacturer.



--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
 
>  Regarding a negative pulse I have no clue what they mean either.  But if the PWM pulse needs to be inverted you can do that by complementing the duty cycle value (y=255-x).  So for example a duty cycle 90% high pulse can also be thought of as a 10% low going pulse.
Group: DynoMotion Message: 1912 From: Tom Kerekes Date: 10/10/2011
Subject: Re: Mach3 speed control w/ brushless motor driver
Hi,
 
Those terms don't really apply in this case because the KFLOP pwm is not actually driving the amplifier's switches.  It is just telling the amplifier the desired speed.
 
Yes you should request the voltage thresholds and current requirements for those inputs.
 
Regards
TK